<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <script src="https://cdn.jsdelivr.net/npm/vue@2.7.10/dist/vue.js"></script>
  <title>Document</title>
</head>

<body>
  <div id="app">
    <h2>{{name}}</h2>
    <hr>
    {{ipt}}
    <hr>
    <!-- <ml-input :value="ipt" @input="gn"></ml-input> -->
    <!-- <ml-input :value="ipt" @input="ipt = $event"></ml-input> -->


    <ml-input v-model="ipt"></ml-input>
  </div>
  <script>
    let MlInput = {
      template: `<input type="text" :value="value" @input="fn" />`,
      props: ["value"],
      methods: {
        fn(e) {
          this.$emit("input", e.target.value)
        }
      }
    }

    let vm = new Vue({
      el: "#app",
      components: {
        MlInput
      },
      data() {
        return {
          name: "码路",
          ipt: 123
        }
      },
      methods: {
        gn(val) {
          console.log("收到了子传递过来的数据：", val);
          this.ipt = val
        }
      },
    });
  </script>
</body>

</html>
<!-- 

    总结在vue2中使用v-model:
      1）v-model写在普通的input标签上，等价于 :value + @input  前提是input 中的type是text
      2）v-model写在组件上，等价于：:value + @input


 -->